package com.fee1in;

import java.io.InputStream;
import java.io.Reader;

/**
 * @author linhui
 */
public class SqlSessionFactoryBuilder {

    String resource;
    Reader reader;


    public SqlSessionFactoryBuilder setResource(String resource) {
        this.resource = resource;
        return this;
    }


    public SqlSessionFactory build() {

        if (resource == null) {
            throw new RuntimeException("resource  can not be null");
        }

        try (InputStream is = getClass().getClassLoader().getResourceAsStream(resource)) {
            XMLConfigBuilder parser = new XMLConfigBuilder();
            Configuration configuration = parser.parse(is);
            return new SqlSessionFactory(configuration);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;


    }


}
